(function () {
  var container = document.querySelector('#content-container');

  function clacScale() {
    const designWidth = 1920;
    const designHeight = 1080;
    const Width = window.innerWidth || document.documentElement.clientWidth;
    const Height = window.innerHeight || document.documentElement.clientHeight;
    let scaleHeight = (Height / designHeight).toFixed(3);
    container.style.transform = `scale(${scaleHeight})`;

    if( (designWidth / scaleHeight) < Width  ){
      $('#swiperWrapper').width( (Width/scaleHeight) + 'px' ).css('marginLeft', (-(Width / scaleHeight - designWidth) / 2) + 'px')
      $('#swiperWrapper1').width( (Width/scaleHeight) + 'px').css('marginLeft', (-(Width / scaleHeight - designWidth) / 2) + 'px')
    }else{
      $('#swiperWrapper').width((designWidth / scaleHeight) + 'px').css('marginLeft', (-(designWidth / scaleHeight - designWidth) / 2) + 'px')
      $('#swiperWrapper1').width((designWidth / scaleHeight) + 'px').css('marginLeft', (-(designWidth / scaleHeight - designWidth) / 2) + 'px')
      $('html').css('overflowX','hidden')
    }

    $('.screen-container-wrapper').each((key, item) => {
      if (item.className.indexOf('carinfo-pop') > -1) {
        item.style.transform = `scale(${scaleHeight}) translateY(-50%)`
      }else{
        item.style.transform = `scale(${scaleHeight})`
      }
    })


    // 此屏设计 保证宽度撑满 高度任意 下填充黑色
    // 如果设计图等比缩放后的宽度 小于页面宽度。 要把整个div移过去居中
    if(designWidth*scaleHeight < Width){
      window.outter = true;
      container.style.position = 'absolute';
      container.style.left= (Width-(designWidth*scaleHeight))/2+'px';
    }else if(designWidth*scaleHeight > Width){
      container.style.position = '';
      container.style.left = '';
      let scaleHeight = downFloat((Width / designWidth).toFixed(2));
      container.style.transform = `scale(${scaleHeight})`;
      container.style.position = 'absolute';
      if( scaleHeight * designWidth < Width ){
        container.style.left = ~~(( scaleHeight * designWidth - Width )/2)  +'px'
      }
    }else{
      window.outter = true;
      container.style.position = 'absolute';
      container.style.left= 0
    }
  }

  let timer = null;
  function resizeHandler() {
    timer && clearTimeout(timer);
    timer = setTimeout(clacScale, 300);
  }

  clacScale();

  window.addEventListener('resize', function(){resizeHandler()});
})();
